package com.xinnet.mms.config.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import com.xinnet.core.dao.impl.BaseDaoImpl;
import com.xinnet.mms.config.dao.FlowTurnConfigDao;
import com.xinnet.mms.entity.Product;
import com.xinnet.mms.entity.PublicConfig;

@Repository("flowTurnConfigDao")
public class FlowTurnConfigDaoImpl extends BaseDaoImpl<Product,Long> implements FlowTurnConfigDao {

	/**取得产品设置信息集合*/
	@Override
	public List<Product> getProductConfig() throws SQLException {
		List<Product> list=this.getSqlSession().selectList("config.getProductConfig");
		if(list.isEmpty())
			return null;
		return list;
	}

	/**修改产品流转规则*/
	@Override
	public void updateflowConfig(Product product) throws SQLException {
		this.getSqlSession().update("config.updateflowConfig",product);
	}

	/**根据产品ID取得产品信息*/
	@Override
	public Product getProductById(@Param(value="id") String id) throws SQLException {
		return this.getSqlSession().selectOne("config.getProductConfigById",id);
	}

	/**增加产品历史*/
	@Override
	public void addProductHistoryFromConfig(Product product) throws SQLException {
		this.getSqlSession().insert("config.addProductHistoryFromConfig",product);
	}

	/**修改所有产品线的二次开发停顿期*/
	@Override
	public void updateMiddleServiceCycle(@Param(value="middleServiceCycle") int MiddleServiceCycle) throws SQLException {
		this.getSqlSession().update("config.updateMiddleServiceCycle",MiddleServiceCycle);
		this.getSqlSession().update("config.updateMiddleServiceCycleUse");
	}

	/**查询产品优先级列表*/
	@Override
	public List<Product> getProductPriority() throws SQLException {
		return this.getSqlSession().selectList("config.getProductPriority");
	}

	/**取得产品设置信息集合 (审核状态)*/
	@Override
	public List<Product> getAuditProductConfig() throws SQLException {
		List<Product> list=this.getSqlSession().selectList("config.getAuditProductConfig");
		if(list.isEmpty())
			return null;
		return list;
	}

	/**设置产品规则为审核通过*/
	@Override
	public void updateProductAuditYes(String id) throws SQLException {
		this.getSqlSession().update("config.updateProductAuditYes",id);
	}

	/**设置产品规则为审核不通过*/
	@Override
	public void updateProductAuditNo(String id) throws SQLException {
		this.getSqlSession().update("config.updateProductAuditNo",id);
	}

	/**修改二次开发停顿期 加入审批*/
	@Override
	public void updateMiddleServiceCycleAddCheck(int day) throws SQLException {
		this.getSqlSession().update("config.updateMiddleServiceCycleAddCheck",day);
	}

	/**查询二次开发停顿期*/
	@Override
	public PublicConfig getMiddleServiceCycleInCheck() throws SQLException {
		return this.getSqlSession().selectOne("config.getMiddleServiceCycleInCheck");
	}

	/**审批二次开发停留期为拒绝*/
	@Override
	public void updateMiddleServiceCycleAuditNo() throws SQLException {
		this.getSqlSession().update("config.updateMiddleServiceCycleAuditNo");
	}

	/**取得业绩保留期*/
	@Override
	public PublicConfig getPerfDayInCheck() throws SQLException {
		return this.getSqlSession().selectOne("config.getPerfDayInCheck");
	}

	/**修改业绩保留期加入审核*/
	@Override
	public void updatePerfDayInCheck(int day) throws SQLException {
		this.getSqlSession().update("config.updatePerfDayInCheck",day);
	}

	/**确认设置优先级*/
	@Override
	public void updatePriority(Product product) throws SQLException {
		this.getSqlSession().update("config.updatePriority",product);
	}

	/**审批二次开发停留期为通过*/
	@Override
	public void updateMiddleServiceCycleAuditYes() throws SQLException {
		this.getSqlSession().update("config.updateMiddleServiceCycleAuditYes");
	}

	/**审批业绩保留期为拒绝*/
	@Override
	public void updatePerfDayAuditNo() throws SQLException {
		this.getSqlSession().update("config.updatePerfDayAuditNo");
	}

	/**审批业绩保留期为通过*/
	@Override
	public void updatePerfDayAuditYes() throws SQLException {
		this.getSqlSession().update("config.updatePerfDayAuditYes");
	}

	/**将产品优先级加入审核*/
	@Override
	public void updatePriorityAddCheck() throws SQLException {
		this.getSqlSession().update("config.updatePriorityAddCheck");
	}

	/**设置产品优先级为审核通过*/
	@Override
	public void updatePriorityAuditYes() throws SQLException {
		this.getSqlSession().update("config.updatePriorityAuditYes");
	}

	/**设置产品优先级为审核拒绝*/
	@Override
	public void updatePriorityAuditNo() throws SQLException {
		this.getSqlSession().update("config.updatePriorityAuditNo");
	}

	/**取得产品优先级审核状态*/
	@Override
	public PublicConfig getPriorityInCheck() throws SQLException {
		return this.getSqlSession().selectOne("config.getPriorityInCheck");
	}

	/**取得到期预警时间*/
	@Override
	public PublicConfig getWarningTime() throws SQLException {
		return this.getSqlSession().selectOne("config.getWarningTime");
	}

	/**修改到期预警时间*/
	@Override
	public void updateWarningTime(int time) throws SQLException {
		this.getSqlSession().update("config.updateWarningTime",time);
	}

	/**获取分配优先级产品列表*/
	@Override
	public List<Product> getAllotPriority() throws SQLException {
		return this.getSqlSession().selectList("config.getAllotPriority");
	}

	/**取得分配默认产品*/
	@Override
	public PublicConfig getDefaultProduct() throws SQLException {
		return this.getSqlSession().selectOne("config.getDefaultProduct");
	}

	/**修改分配默认产品*/
	@Override
	public void updateDefaultProduct(String productId) throws SQLException {
		this.getSqlSession().update("config.updateDefaultProduct",productId);
	}

	/**修改分配优先级*/
	@Override
	public void updateAllotPriority(Product product) throws SQLException {
		this.getSqlSession().update("config.updateAllotPriority",product);
	}
	
	/**
	 * 获取可用的业绩保留期
	 * @return
	 */
	public PublicConfig getEnablePerfDayInCheck(){
		return this.getSqlSession().selectOne("config.getEnablePerfDayInCheck");	
	}

	/**
	 * 取得即将流走客户提醒设置
	 */
	@Override
	public PublicConfig getPublicRemind() throws SQLException {
		return this.getSqlSession().selectOne("config.getPublicRemind");
	}

	/**
	 * 设置即将流走客户提醒时间
	 */
	@Override
	public PublicConfig updatePublicRemind(Integer remind) throws SQLException {
		return this.getSqlSession().selectOne("config.updatePublicRemind",remind);
	}
	
}
